package com.oa.wk.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.oa.domain.Dept;
import com.oa.wk.service.DeptService;
import com.opensymphony.xwork2.ActionSupport;

public class DeptAction extends ActionSupport {
	
	private DeptService deptService;
	
	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}
	/**
	 * ��ѯ����������Ϣ
	 * */

	private List<Dept> depts;
	
	public List<Dept> getDepts() {
		return depts;
	}
	
	public String execute() throws Exception {
		
		depts = deptService.getDept();
		return SUCCESS;
	}
	
	
	
	private Dept dept;

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}
	
public String addDept() throws Exception {
		System.out.println(dept.getDname());
		System.out.println(dept.getDinfo());
		deptService.addDept(dept);
		return SUCCESS;
	}

public String getInfo(){
	System.out.println(ServletActionContext.getRequest().getParameter("deptno"));
	List<Dept> list = (List<Dept>) deptService.getDeptDeptno(Integer.parseInt(ServletActionContext.getRequest().getParameter("deptno")));
	System.out.println("list:"+list.size());
	ServletActionContext.getRequest().setAttribute("list", list);
	return "GOUPD";
	
  }
public String updInfo(){
	deptService.updateDeptDeptno(dept);
	return SUCCESS;
}
public String delInfo(){
	Dept dept = new Dept();
	dept.setDeptno(Integer.parseInt(ServletActionContext.getRequest().getParameter("deptno")));
	System.out.println(Integer.parseInt(ServletActionContext.getRequest().getParameter("deptno")));
	deptService.deleteDeptDeptno(dept);
	return SUCCESS;
}

}
